package com.zky.gulimall.product;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Description TODO
 * @Author 张开源
 * @Date 2022/11/12 12:03
 * @Version 1.0
 **/
public class VolatileNoAtomicDemo {
    public static void main(String[] args) {
        AtomicReference<MyNumber> atomicReference=new AtomicReference<>();
        MyNumber number = new MyNumber();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    number.addPlus();
                }
            }, String.valueOf(i)).start();
        }

        try {
            TimeUnit.MILLISECONDS.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(number.number);

    }

    static class MyNumber {
        int number;

        public  void addPlus() {
            number++;
        }
    }
}
